import request from '@/utils/request'

const jobApi = '/quartzJob'

/**
 * 获取定时任务列表
 * @param params
 * @returns {AxiosPromise}
 */
export const listJob = (params) => {
  return request({
    url: `${jobApi}/list`,
    method: 'GET',
    params
  })
}

/**
 * 分页查询定时任务列表
 * @param params
 * @returns {AxiosPromise}
 */
export const pageJob = (params) => {
  return request({
    url: `${jobApi}`,
    method: 'GET',
    params
  })
}

/**
 * 新增定时任务
 * @param data 定时任务数据
 * @returns {AxiosPromise}
 */
export const addJob = (data) => {
  return request({
    url: `${jobApi}`,
    method: 'POST',
    data
  })
}


/**
 * 根据id查询定时任务信息
 * @param id 定时任务id
 * @returns {AxiosPromise}
 */
export const getJob = (id) => {
  return request({
    url: `${jobApi}/${id}`,
    method: 'GET'
  })
}


/**
 * 根据ID删除定时任务
 * @param id 定时任务id
 * @returns {AxiosPromise}
 */
export const delJob = (id) => {
  return request({
    url: `${jobApi}/${id}`,
    method: 'DELETE'
  })
}

/**
 * 根据ID修改定时任务名称
 * @param data 定时任务数据
 * @returns {AxiosPromise}
 */
export const updateJob = (data) => {
  return request({
    url: `${jobApi}/${data.jobId}`,
    method: 'PUT',
    data
  })
}

/**
 * 定时任务立即执行一次
 * @param jobId
 * @param jobGroup
 * @returns {AxiosPromise}
 */
export const runJob = (jobId) => {
  return request({
    url: `${jobApi}/run/${jobId}`,
    method: 'PUT',
  })
}

/**
 * 任务状态修改
 * @param jobId
 * @param jobGroup
 * @returns {AxiosPromise}
 */
export const changeJobStatus = (jobId, status) => {
  const data = {
    jobId,
    status
  }
  return request({
    url: `${jobApi}/changeStatus`,
    method: 'PUT',
    data
  })
}
